import 'package:flutter/material.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:google_fonts/google_fonts.dart';
import 'animated_tap_widget.dart';

/// 举报对话框组件
class ReportDialog extends StatelessWidget {
  final String title;
  final String content;
  final VoidCallback? onReportSuccess;

  const ReportDialog({
    super.key,
    this.title = 'Report Content',
    this.content = 'Please select a reason for reporting this content',
    this.onReportSuccess,
  });

  /// 显示举报对话框
  static Future<void> show(
    BuildContext context, {
    String title = 'Report Content',
    String content = 'Please select a reason for reporting this content',
    VoidCallback? onReportSuccess,
  }) {
    return showDialog<void>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return ReportDialog(
          title: title,
          content: content,
          onReportSuccess: onReportSuccess,
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      child: ConstrainedBox(
        constraints: BoxConstraints(
          maxHeight: MediaQuery.of(context).size.height * 0.8,
        ),
        child: Container(
          decoration: BoxDecoration(
            color: const Color(0xFF663507),
            borderRadius: BorderRadius.circular(16.r),
            border: Border.all(color: const Color(0xFFFF8A3C), width: 1.w),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              // 标题栏
              Container(
                padding: EdgeInsets.all(20.w),
                decoration: BoxDecoration(
                  color: const Color(0xFFFF8A3C),
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(16.r),
                    topRight: Radius.circular(16.r),
                  ),
                ),
                child: Row(
                  children: [
                    Expanded(
                      child: Text(title)
                          .fontSize(18.sp)
                          .textColor(Colors.white)
                          .fontFamily(
                            GoogleFonts.roboto(
                              fontWeight: FontWeight.w700,
                            ).fontFamily,
                          )
                          .fontWeight(FontWeight.w700)
                          .textAlignment(TextAlign.center),
                    ),
                    AnimatedTapWidget(
                      onTap: () => Navigator.of(context).pop(),
                      child: Icon(Icons.close, color: Colors.white, size: 24.w),
                    ),
                  ],
                ),
              ),

              // 内容区域
              Flexible(
                child: Padding(
                  padding: EdgeInsets.all(20.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      // 说明文字
                      Text(content)
                          .fontSize(14.sp)
                          .textColor(Colors.white.withOpacity(0.8))
                          .fontFamily(
                            GoogleFonts.quicksand(
                              fontWeight: FontWeight.w500,
                            ).fontFamily,
                          )
                          .fontWeight(FontWeight.w500),

                      SizedBox(height: 16.h),

                      // 举报选项列表
                      ..._buildReportOptions(context),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 构建举报选项列表
  List<Widget> _buildReportOptions(BuildContext context) {
    final reportOptions = [
      'Inappropriate Content',
      'Hate Speech',
      'Disturbing Content',
      'Illegal Activity',
      'Spam/Advertisement',
      'Other Issues',
      'Block User',
    ];

    return reportOptions.map((option) {
      return Container(
        margin: EdgeInsets.only(bottom: 8.h),
        child: AnimatedTapWidget(
          onTap: () => _handleReportOption(context, option),
          child: Container(
            padding: EdgeInsets.symmetric(vertical: 12.h, horizontal: 16.w),
            decoration: BoxDecoration(
              color: Colors.white.withOpacity(0.1),
              borderRadius: BorderRadius.circular(12.r),
              border: Border.all(
                color: Colors.white.withOpacity(0.2),
                width: 1.w,
              ),
            ),
            child: Row(
              children: [
                Expanded(
                  child: Text(option)
                      .fontSize(15.sp)
                      .textColor(Colors.white)
                      .fontFamily(
                        GoogleFonts.quicksand(
                          fontWeight: FontWeight.w600,
                        ).fontFamily,
                      )
                      .fontWeight(FontWeight.w600),
                ),
                Icon(
                  Icons.arrow_forward_ios,
                  color: Colors.white.withOpacity(0.5),
                  size: 14.w,
                ),
              ],
            ),
          ),
        ),
      );
    }).toList();
  }

  /// 处理举报选项选择
  void _handleReportOption(BuildContext context, String option) {
    Navigator.of(context).pop();

    // 执行成功回调
    onReportSuccess?.call();
  }
}
